<?php
class User_model extends CI_Model {
	public function __construct() {
		parent::__construct();
	}

	public function create($userData = FALSE) {
		if (!$userData) {
			return FALSE;
		}

		$count = $this->db
		              ->from('users')
		              ->where('username', $userData['username'])
		              ->count_all_results();
		if ($count > 0) {
			return FALSE;
		}
		$pepper = bin2hex(openssl_random_pseudo_bytes(32));
		$passhash = hash('sha256', $pepper . $userData['password']);

		$this->db
		     ->insert('users', array(
			     'username' => $userData['username'],
			     'passhash' => $passhash,
			     'pepper' => $pepper,
			     'name' => $userData['name'],
		     ));
		return TRUE;
	}
}